<?php 
declare (strict_types = 1);
namespace app\api\controller;
use app\common\controller\Api;
use think\Request;
class BusinessHostComment extends Api
{
    protected $with = ['user_index'];
    //商户端-DM管理列表-评论列表
    public function index()
    {
        $this->businessCheckLogin();
        $post = param();
        $limit = input('limit') ?: 20;
        if(!isset($post['status']) || !isset($post['id'])) return msgerror('参数缺失');
        $where = [
            ['business_host_id','=',$post['id']],
            ['status','=',$post['status']],
        ];
        $data = $this->model->where($where)->with($this->with)->order('id desc')->paginate($limit);
        new_urladd($data);
        return datasuccess($data);
    }
    //用户端-评论
    public function add()
    {
        $this->checkLogin();
        $post = param();
        //主持人ID，评论，轮播图images
        if(!isset($post['id']) || !isset($post['content'])) return msgerror('参数缺失');
        $data = ['business_host_id'=>$post['id'],'user_index_id'=>$this->userinfo['id'],'content'=>$post['content'],'status'=>1,'images'=>($post['images']??'')];
        $this->model->save($data);
        return datasuccess([],'评论成功');
    }
}